package com.cz.nongyetongv5.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.custom.wheelview.Utils;

import java.util.List;

public class GoHomeUtil {

	public static View createPopView(Context context, String[] texts) {

		LinearLayout linearLayout = new LinearLayout(context);

		linearLayout.setBackgroundResource(R.color.title_color);

		linearLayout.setLayoutParams(new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT));

		linearLayout.setOrientation(LinearLayout.VERTICAL);

		for (int i = 0; i < texts.length; i++) {

			// ���ư�ť

			Button button = new Button(context);

			button.setTag("btn" + i);

			button.setLayoutParams(new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT));

			button.setBackgroundResource(R.drawable.btn_back_pressed);

			button.setText(texts[i]);

			button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

			button.setTextColor(Color.WHITE);

			int left = Utils.dip2px(context, 18);

			int right = left;

			int top = Utils.dip2px(context, 8);

			int bottom = top;

			button.setPadding(left, top, right, bottom);

			linearLayout.addView(button);

			if (i < texts.length - 1) {

				View v = new View(context);

				v.setLayoutParams(new LinearLayout.LayoutParams(
						LinearLayout.LayoutParams.MATCH_PARENT, 1));

				v.setBackgroundColor(Color.WHITE);

				linearLayout.addView(v);

			}

		}

		return linearLayout;

	}

	public static void goHome(Context context) {

		InitApplication initApplication = (InitApplication) context
				.getApplicationContext();

		List<Activity> activities = initApplication.getActivities();

		for (int i = 1; i < activities.size(); i++) {

			activities.get(i).finish();

		}

	}
}
